﻿@typeparam TData

<RadioGroup @bind-Value="Value" OnChange="EventCallback.Factory.Create<TData>(this, SetValue)">
    @CreateEnemu()
</RadioGroup>
@code{
    TData _value;
    [Parameter]
    public TData Value { get; set; }
    [Parameter]
    public EventCallback<TData> ValueChanged { get; set; }

    [Parameter]
    public EventCallback<TData> OnChange { get; set; }

    public async void SetValue()
    {
        if (ValueChanged.HasDelegate)
        {
            await ValueChanged.InvokeAsync(Value);
        }
        if (OnChange.HasDelegate)
        {

            await OnChange.InvokeAsync(Value);
        }

    }

    public RenderFragment CreateEnemu()
    {
        var type = typeof(TData);
        if (!type.IsEnum) throw new Exception("Only enumeration types can be entered");
        var dic = CommonlyHelper.GetEnenuModelHeader(type);
        RenderFragment render = null;
        foreach (var item in dic)
        {
            render +=@<Radio  Value="(TData)Enum.ToObject(type, item.Key)">@item.Value</Radio>;
        }
        return render;
    }
}